import type { APIEvent } from "@solidjs/start" import type { DownloadPlatform } from "../types" const prodAssetNames: Record = { "darwin-aarch64-dmg": "opencode-desktop-darwin-aarch64.dmg", "darwin-x64-dmg": "opencode-desktop-darwin-x64.dmg", "windows-x64-nsis": "opencode-desktop-windows-x64.exe", "linux-x64-deb": "opencode-desktop-linux-amd64.deb", "linux-x64-appimage": "opencode-desktop-linux-amd64.AppImage", "linux-x64-rpm": "opencode-desktop-linux-x86_64.rpm", } satisfies Record const betaAssetNames: Record = { "darwin-aarch64-dmg": "opencode-desktop-mac-arm64.dmg", "darwin-x64-dmg": "opencode-desktop-mac-x64.dmg", "windows-x64-nsis": "opencode-desktop-win-x64.exe", "linux-x64-deb": "opencode-desktop-linux-amd64.deb", "linux-x64-appimage": "opencode-desktop-linux-x86_64.AppImage", "linux-x64-rpm": "opencode-desktop-linux-x86_64.rpm", } satisfies Record // Doing this on the server lets us preserve the original name for platforms we don't care to rename for const downloadNames: Record = { "darwin-aarch64-dmg": "OpenCode Desktop.dmg", "darwin-x64-dmg": "OpenCode Desktop.dmg", "windows-x64-nsis": "OpenCode Desktop Installer.exe", } satisfies { [K in DownloadPlatform]?: string } export async function GET({ params: { platform, channel } }: APIEvent) { const assetName = channel === "stable" ? prodAssetNames[platform] : betaAssetNames[platform] if (!assetName) return new Response(null, { status: 404 }) const resp = await fetch( `https://github.com/anomalyco/${channel === "stable" ? "opencode" : "opencode-beta"}/releases/latest/download/${assetName}`, { cf: { // in case gh releases has rate limits cacheTtl: 60 * 5, cacheEverything: true, }, } as any, ) const downloadName = downloadNames[platform] const headers = new Headers(resp.headers) if (downloadName) headers.set("content-disposition", `attachment; filename="${downloadName}"`) return new Response(resp.body, { status: resp.status, statusText: resp.statusText, headers }) }